package com.cike.productmanager.DBHelper;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;
import android.widget.Toast;

public class ExguideInfoContentHandler extends DefaultHandler {

    private static final String TAG = "DisplayGuideInfoContentHandler";
    private List<ExguideInfo> exguideInfos;
    private ExguideInfo exguideInfo;
    private String preTag;

    public List<ExguideInfo> getExguideInfos() {
        return exguideInfos;
    }
    
    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {
        
        String data = null;
        
        if(exguideInfo != null){
            if("id".equals(preTag)){
                data = new String(ch, start, length);
                exguideInfo.id = data;
            }
            else if ("No".equals(preTag)) {
                data = new String(ch, start, length);
                exguideInfo.No = data;
            }
            else if ("name".equals(preTag)) {
                data = new String(ch, start, length);
                exguideInfo.name = data;
            }
            else if ("imgpath".equals(preTag)) {
                data = new String(ch, start, length);
                exguideInfo.imgpath = data;
            }
            else if ("remark".equals(preTag)) {
                data = new String(ch, start, length);
                exguideInfo.remark = data;
            }
            else if ("type".equals(preTag)) {
                data = new String(ch, start, length);
                exguideInfo.type = data;
            }
            
            
            Log.i(TAG, "�������ݣ�"+new String(ch, start,length));
        }
    }
    
    
    @Override
    public void endDocument() throws SAXException {
        super.endDocument();
        Log.i(TAG, "�ĵ��������");
    }
    
    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {
        if ("exguide".equals(localName)&&exguideInfo!=null)
        {
            exguideInfos.add(exguideInfo);
            exguideInfo = null;
        }
        String tag=preTag;
        preTag = null;
        Log.i(tag, localName + "�������");
    }
    
    @Override
    public void startDocument() throws SAXException {
        exguideInfos = new ArrayList<ExguideInfo>();
        Log.i(TAG, "��ʼ����...");
    }
    
    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {
        try {
            if ("exguide".equals(localName)) {
                exguideInfo = new ExguideInfo();
            }
            preTag = localName;
        } catch (Exception e) {
            // TODO: handle exception
            Toast.makeText(null, "�����¼ʧ��", Toast.LENGTH_SHORT);
        }
    }
}
